<!DOCTYPE html>
<html>
<!--
  Copyright 2018 The Chromium Authors. All rights reserved.
  Use of this source code is governed by a BSD-style license that can be
  found in the LICENSE file.
-->
<head>
<!-- Verify the storeName / key-0 blob key is present
     and blob value matches what was written during setup. -->
<title>IDB test for v2schema corruption - verify</title>
<script type="text/javascript" src="common.js"></script>
<script>

function test() {
  const dbname = "v2schemacorrupt_setup.html";
  const request = indexedDB.open(dbname);
  request.onsuccess = onSuccess;
  request.onerror = unexpectedErrorCallback;
  request.onblocked = unexpectedBlockedCallback;
}

function onSuccess(event) {
  db = event.target.result;
  debug("Verify object store exists");
  shouldBe("db.objectStoreNames.length", "1");
  const transaction = db.transaction("storeName", "readonly");
  const objectStore = transaction.objectStore("storeName");
  const request = objectStore.get("key-0");
  request.onsuccess = (requestSuccessEvent) => {
    const reader = new FileReader();
    reader.addEventListener("loadend", () => {
      if (reader.result !== "abc") {
        fail(`expected blob to contain 'abc', got '${reader.result}'`);
        return;
      }
      done();
    });
    reader.readAsText(request.result.blob);
  };
  request.onerror = () => { fail("onerror called"); };
}

</script>
</head>
<body onLoad="test()">
<div id="status">Starting...</div>
</body>
</html>
